<%--
  Created by IntelliJ IDEA.
  User: 。
  Date: 2019-12-05
  Time: 10:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%String type = request.getParameter("type");%>
<html>
<head>
    <title><%=type%>新闻</title>
    <style type="text/css">
        .newsbox {
            width: 80%;
            height: auto;
            margin: 3% auto;
            padding: 1% 3% 1% 3%;
            color: black;
            background-color: #E6E6E6;
        }

        .newsbox a {
            color: black;
        }

        .newsbox a:hover {
            color: red;
        }

        .newsbox p {
            color: black;
        }
        .newsbox tr{
            height: 50px;
        }
        .newsbox td{
            text-align: center;
            padding: 20px;
            font-size: 20px;
        }
    </style>
</head>
<body>
<jsp:include page="head.jsp"/>
<div class="newsbox">
    <table border="1" style="border-collapse: collapse;">
        <tr>
            <td style="width: 664px;height: 50px; text-align: center; font-size: 24px;" ><p>标题</p></td>
            <td style="width: 1236px;height: 50px; text-align: center; font-size: 24px;" ><p>介绍</p></td>
        </tr>
        <%
            try {
                Class.forName("com.mysql.jdbc.Driver");
                String url = "jdbc:mysql://localhost:3306/news?serverTimezone=UTC";
                String username1111 = "root";
                String password1111 = "root";
                Connection conn = DriverManager.getConnection(url, username1111, password1111);

                if (conn != null) {
                    Statement stmt = null;
                    ResultSet rs = null;
                    String sql = "SELECT id,title,simply FROM news where type='" + type + "';";  //查询语句
                    stmt = conn.createStatement();
                    rs = stmt.executeQuery(sql);
                    while (rs.next()) {
                        String id = rs.getString("id");
                        String title = rs.getString("title");
                        String simply = rs.getString("simply");
        %>
        <tr>
            <td><a href="news.jsp?id=<%=id%>"><%=title%>
            </a></td>
            <td><p><%=simply%><p></p></td>
        </tr>
        <%
                    }
                }
            } catch (Exception e) {
                out.print(e);
            }
        %>
    </table>
</div>
<jsp:include page="bottom.jsp"/>
</body>
</html>
